package com.cershy.chatroomserver.controller;

import cn.hutool.json.JSONObject;
import com.cershy.chatroomserver.annotation.UrlFree;
import com.cershy.chatroomserver.annotation.UrlLimit;
import com.cershy.chatroomserver.constant.LimitKeyType;
import com.cershy.chatroomserver.service.RegisterService;
import com.cershy.chatroomserver.utils.ResultUtil;
import com.cershy.chatroomserver.vo.register.RegisterVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

@RestController
@RequestMapping("/api/v1/register")
public class RegisterController {

    @Resource
    private RegisterService registerService;

    @UrlFree
    @PostMapping("")
    @UrlLimit(keyType = LimitKeyType.IP)
    public Object register(@RequestBody @Valid RegisterVo registerVo) {
        JSONObject result = registerService.register(registerVo);
        return ResultUtil.Succeed(result);
    }
}
